package com.edu.backend.exception;


import com.edu.backend.utils.R;
import com.edu.backend.utils.ResultCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.client.HttpClientErrorException.BadRequest;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R handleGlobalError(Exception e) {
        e.printStackTrace();
        return R.error().code(ResultCode.ERROR).message("服务器出错，请重试...");
    }

    @ExceptionHandler(BadRequest.class)
    public R handleBadRequest() {
        return R.error().code(ResultCode.ERROR).message("请求非法!");
    }

    @ExceptionHandler(EduException.class)
    public R handleGuliException(EduException e) {
        e.printStackTrace();

        return R.error().code(ResultCode.ERROR).message(e.getMsg());
    }
}
